package com.derbysoft.ota.application.translator.rq;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.ota.application.translator.CodeTables;
import com.derbysoft.remote.dswitch.generic.constants.CardType;
import com.google.common.base.Preconditions;
import com.googlecode.functionalcollections.FunctionalIterable;
import com.googlecode.functionalcollections.FunctionalIterables;

import java.util.HashMap;
import java.util.Map;

public class CardTypeTranslator implements Translator<String, CardType> {

	private static Map<String, CardType> map = new HashMap<String, CardType>();
	static {
		map.put(CodeTables.CDT_CREDIT, CardType.CREDIT);
		map.put(CodeTables.CDT_DEBIT, CardType.DEBIT);
		map.put(CodeTables.CDT_CENTRAL_BILL, CardType.CENTRAL_BILL);
	}

	public CardType translate(String source) {
		return Preconditions.checkNotNull(map.get(source),
				"Unsupported PaymentCardCodeType [" + source + "], "
					+ "supported values are taken from CardType(CDT) in OpenTravel_CodeTable.xsd : "
					+ supportedValues());
	}

	private FunctionalIterable<String> supportedValues() {
		return FunctionalIterables.<String>create()
				.concat(CodeTables.CDT_CREDIT)
				.concat(CodeTables.CDT_DEBIT)
				.concat(CodeTables.CDT_CENTRAL_BILL);
	}
}
